//C file
/***********************************************
#      Copyright(C):2017
#      luminqi<lumqi@foxmail.com>
#      All rights reserved.
#
#      Filename: led_test.c
#
#        Author: luminqi<lumqi@foxmail.com>
#   Description: 
#        Create: 2017-04-09 23:57:14
# Last Modified: 2017-04-09 23:57:35
***********************************************/
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>


#define LED_CNT        4
#define DEVNAME_LEN    10

#define PLATDRV_MAGIC             0x60
#define LED_OFF                   _IO (PLATDRV_MAGIC, 0x18)
#define LED_ON                    _IO (PLATDRV_MAGIC, 0x19)


int main (int argc, char **argv)
{
    int           i;
    int           fd[LED_CNT];
    char          dev_name[DEVNAME_LEN]={0,0,0,0};

    for(i=0; i<LED_CNT; i++)
    {
        snprintf(dev_name, sizeof(dev_name), "/dev/led%d", i);
        fd[i] = open(dev_name, O_RDWR, 0755);
        if(fd[i] < 0)
            goto err;
    }

    while(1)
    {
        for(i=0; i<LED_CNT; i++)
        {
            ioctl(fd[i], LED_ON);
        }
        sleep(1);

        for(i=0; i<LED_CNT; i++)
        {
            ioctl(fd[i], LED_OFF);
        }
        sleep(1);
    }

    for(i=0; i<LED_CNT; i++)
    {
        close(fd[i]);
    }

    return 0;

err:
    for(i=0; i<LED_CNT; i++)
    {
        if(fd[i] >= 0)
        {
            close(fd[i]);
        }
    }
    return -1;
} /* ----- End of main() ----- */

